package com.javaee.xiangyang.mapper;

import com.javaee.xiangyang.entity.Classify;
import com.javaee.xiangyang.entity.Goods;
import com.javaee.xiangyang.util.SQLProviderUtil;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface GoodsMapper {

    /**
     * 新增商品
     */
//    @Insert("insert into goods values(#{goodsId}, #{goodsName}, #{goodsImg}, #{goodsPrice}, #{goodsIntroduce}, #{goodInventory}, #{goodsClassifyId})")
    void addGoods(Goods goods);

    /**
     * 查看所有商品
     */
//    @Select("select * from goods")
//    @Results(id = "Goods", value = {
//            @Result(id = true, column = "goodsId", property = "goodsId"),
//            @Result(
//                    column = "goodsClassifyId",
//                    property = "classify",
//                    javaType = Classify.class,
//                    one = @One(select = "com.javaee.xiangyang.mapper.ClassifyMapper.findByClassifyId")
//            )
//    })
    List<Goods> findAllGoods();

    /**
     * 根据商品类别查看所有商品
     */
//    @Select("select * from goods where goodsClassifyId = #{classifyId}")
//    @ResultMap("Goods")
    List<Goods> findAllGoodsByClassifyId(Classify classify);

    /**
     * 此接口只给GoodsMapper接口开放
     */
//    @Select("select * from goods where goodsClassifyId = #{goodsClassifyId}")
    List<Goods> findAllGoodsById(int goodsClassifyId);

    /**
     * 根据商品ID查询商品具体信息
     */
//    @Select("select * from goods where goodsId = #{goodsId}")
//    @ResultMap("Goods")
    Goods findGoodsByGoodsId(Goods goods);

    /**
     * 根据生成订单数量最多的商品排序
     * 返回排序后商品ID集合
     */
    List<Integer> findGoodsByNumber();

    /**
     * 模糊查询
     */
    List<Goods> findGoodsBySomething(@Param("string") String string, @Param("classify") Classify classify);

    /***
     * 根据商品库存量查找
     */
//    @Select("select * from goods where goodsInventory = #{goodsInventory}")
//    @ResultMap("Goods")
    List<Goods> findGoodsByInventory(Goods goods);

    /**
     * 更改商品库存量
     */
//    @UpdateProvider(type = SQLProviderUtil.class, method = "updateInventoryByGoodsId")
    void updateInventoryByGoodsId(@Param("goods") Goods goods, @Param("type") boolean type);

    /**
     * 更改商品信息
     */
//    @Update("update goods set goodsName = #{goodsName}, goodsImg = #{goodsImg}, goodsPrice = #{goodsPrice}, goodsIntroduce = #{goodsIntroduce} where goodsId = #{goodsId}")
    void updateByGoodsId(Goods goods);


}
